package co.id.btel.create.pdf;

import java.io.FileOutputStream;

import utilities.Constants;
import utilities.PdfUtil;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfCustomer {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String FILE = "E:/BTE/samplePdf/Customer.pdf";
		try {
			Document document = new Document();
			PdfWriter.getInstance(document, new FileOutputStream(FILE));
			document.open();
			PdfUtil.addMetaData(document);
			addCustomer(document);
			// addInvoiceInfo(document);
			document.close();
			System.out.print("done!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void addCustomer(Document document) throws DocumentException {

		PdfPTable table = new PdfPTable(3);
		table.setWidthPercentage(100);
		table.setWidths(new int[] { 5, 2, 8 });

		// sel 1
		Paragraph p = new Paragraph();
		Chunk ch = new Chunk("OPRT MONITOR N TROUBLESHOOT",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_D,
						Font.BOLD, BaseColor.BLACK));
		p.add(ch);
		PdfPCell c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 2
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 3
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		c1.addElement(addInvoiceInfo());
		table.addCell(c1);

		// sel 4
		p = new Paragraph(new Chunk("KURNIA YUSUP", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK)));
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 5
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 6 rowspan

		// sel 7
		p = new Paragraph(
				new Chunk(
						"WISMA BAKRIE 1 HR RASUNA SAID KAV B-1 NO.. KARET SETIABUDI JAKARTA SELATAN DKI JAKARTA",
						FontFactory.getFont(FontFactory.HELVETICA,
								Constants.FONT_D, Font.NORMAL, BaseColor.BLACK)));
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 8
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 9 rowspan

		// sel 10
		p = new Paragraph(new Chunk("12920", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK)));
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 11
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 12 rowspan
		p = new Paragraph("");
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setColspan(3);
		table.addCell(c1);

		document.add(table);

	}

	private static PdfPTable addInvoiceInfo() {

		PdfPTable table = new PdfPTable(2);
		table.setWidthPercentage(100);

		// sel 1
		Paragraph p = new Paragraph();
		Chunk ch = new Chunk("No. Invoice | Invoice Number",
				FontFactory.getFont(FontFactory.HELVETICA, Constants.FONT_D,
						Font.NORMAL, BaseColor.BLACK));
		p.add(ch);
		PdfPCell c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 2
		p = new Paragraph();
		ch = new Chunk(": 20120160287", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		table.addCell(c1);

		// sel 3
		p = new Paragraph();
		ch = new Chunk("No. Pelanggan | Subscriber ID", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 4
		p = new Paragraph();
		ch = new Chunk(": 2156116585", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 5
		p = new Paragraph();
		ch = new Chunk("Bulan Tagihan | Billing Month", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 6
		p = new Paragraph();
		ch = new Chunk(": 01 APR 2012", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 7
		p = new Paragraph();
		ch = new Chunk("Periode Tagihan | Billing Period", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 8
		p = new Paragraph();
		ch = new Chunk(": 01 MAR-31 MAR 2012", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 9
		p = new Paragraph();
		ch = new Chunk("Jenis Program | Program Type", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 10
		p = new Paragraph();
		ch = new Chunk(": Esia Operational", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 11
		p = new Paragraph();
		ch = new Chunk("Akhir Pembayaran | Due Date", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		// sel 12
		p = new Paragraph();
		ch = new Chunk(": 20 APR 2012", FontFactory.getFont(
				FontFactory.HELVETICA, Constants.FONT_D, Font.NORMAL,
				BaseColor.BLACK));
		p.add(ch);
		c1 = new PdfPCell(p);
		c1.setBorderWidth(0);
		c1.setRowspan(4);
		table.addCell(c1);

		return table;

	}

}
